var app = new Vue({
  el: '#app',
  data () {
    return {
      msglist: null,
      cartBadge: localStorage.getItem('cartBadge')
    }
  },
  created () {
    this.getMsgData()
  },
  methods: {
    getMsgData () {
      Axios.post('/order/custom/message.do', {}).then(res => {
        if (res.respCode === "S") {
          let list = res.data
          list.forEach(msg => {
            msg.createTime =  new Date(msg.createTime).Format('MM-dd-hh:mm')
          })
          this.msglist = res.data
        }
			}).catch(err => {
        console.error(err)
      })
    },
    clickMsg (index) {
      if (this.msglist[index].viewStatus === "NOT_VIEW") {
        this.changeMsgView(index)
      } else {
        if (this.msglist[index].messageType === "SELF_ORDER"&&this.msglist[index].userType === "USER") {
          window.location.href = "../order/member_order.html?typeid=2"
        } else if (this.msglist[index].messageType === "SELF_ORDER"&&this.msglist[index].userType === "SHARER") {
          window.location.href = "../informationSharing/sharing.html"
        }
      }
    },
    changeMsgView (index) {
      Axios.post('/order/custom/updateMessageStatus.do', {
        messageId: this.msglist[index].messageId,
        viewStatus: this.msglist[index].viewStatus
      }).then(res => {
        if (res.respCode === "S") {
          if (this.msglist[index].messageType === "SELF_ORDER"&&this.msglist[index].userType === "USER") {
            window.location.href = "../order/member_order.html?typeid=2"
          } else if (this.msglist[index].messageType === "SELF_ORDER"&&this.msglist[index].userType === "SHARER") {
            window.location.href = "../informationSharing/sharing.html"
          }
        }
			}).catch(err => {
        console.error(err)
      })
    }
  }
})